<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
            <a-form :form="form" slot="detail">
                <a-row>
                    <a-col :span="24">
                        <a-form-item label="发货企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['deliverCompany']"
                                placeholder="请输入发货企业名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="运输状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-dict-select-tag type="list" v-decorator="['transportStatus']"
                                :trigger-change="true" dictCode="transport_status"
                                placeholder="请选择运输状态" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="车牌号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['plateNo']" placeholder="请输入车牌号"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="挂车号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['trailerNo']" placeholder="请输入挂车号"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="司机姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['driverName']" placeholder="请输入司机姓名"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['idCard']" placeholder="请输入身份证号"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['phoneNum']" placeholder="请输入手机号"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="健康证" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['healthCertificate']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="健康证有效期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择健康证有效期" v-decorator="['healthCertificateDate']"
                                :trigger-change="true" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="其他证件" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['otherCertificate']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="所属运输企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['fleet']" placeholder="请输入所属运输企业名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="收货企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['receiptCompany']"
                                placeholder="请输入收货企业名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="产品种类" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['productionType']"
                                placeholder="请输入产品种类"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="车体是否有食用油专用标签" :labelCol="labelCol"
                            :wrapperCol="wrapperCol">
                            <j-dict-select-tag type="radio" v-decorator="['isEdibleOilLabel']"
                                :trigger-change="true" dictCode="is_edible_oil_label"
                                placeholder="请选择车体是否有食用油专用标签" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前一载卸货公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['lastTimeUnloadingCompanyName1']"
                                placeholder="请输入前一载卸货公司"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前二载卸货公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['lastTimeUnloadingCompanyName2']"
                                placeholder="请输入前二载卸货公司"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前三载卸货公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['lastTimeUnloadingCompanyName3']"
                                placeholder="请输入前三载卸货公司"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前一载卸车货品名称" :labelCol="labelCol"
                            :wrapperCol="wrapperCol">
                            <a-input v-decorator="['lastTimeUnloadingGoodsName1']"
                                placeholder="请输入前一载卸车货品名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前二载卸车货品名称" :labelCol="labelCol"
                            :wrapperCol="wrapperCol">
                            <a-input v-decorator="['lastTimeUnloadingGoodsName2']"
                                placeholder="请输入前二载卸车货品名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前三载卸车货品名称" :labelCol="labelCol"
                            :wrapperCol="wrapperCol">
                            <a-input v-decorator="['lastTimeUnloadingGoodsName3']"
                                placeholder="请输入前三载卸车货品名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前一载卸货日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择前一载卸货日期"
                                v-decorator="['lastTimeUnloadingDate1']" :trigger-change="true"
                                style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前二载卸货日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择前二载卸货日期"
                                v-decorator="['lastTimeUnloadingDate2']" :trigger-change="true"
                                style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前三载卸货日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择前三载卸货日期"
                                v-decorator="['lastTimeUnloadingDate3']" :trigger-change="true"
                                style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="三载卸货照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['lastTimeUnloadingPhotos']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="前三载证明文件" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['documentation']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="上次清洗时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择上次清洗时间" v-decorator="['lastTimeCleaningDate']"
                                :trigger-change="true" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="上次清洗证明和发票" :labelCol="labelCol"
                            :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['lastTimeCleaningPhotos']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="产品合格证" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['certificate']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="产品标签" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['productLabel']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="gps截图" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['screenshot']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="司机签字" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['driverSign']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="入场磅单" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['poundListPhoto1']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="入场铅封" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['leadSealingPic1']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="车身照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['vehiclePhoto']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="车头照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['vehicle45Photo']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="车尾照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['back45Photo']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="取样照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['samplingPhoto']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="铅封照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['leadSealingPic']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="随车装运记录" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['onboardRecordForm']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="磅单照片" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-image-upload isMultiple
                                v-decorator="['poundListPhoto']"></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="重量(吨)" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['weight']" placeholder="请输入重量(吨)"
                                disabled></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="三载审核人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['auditName1']" placeholder="请输入三载审核人"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="三载审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择三载审核时间" v-decorator="['auditTime1']"
                                :trigger-change="true" :show-time="true"
                                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="安检审核人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['auditName2']" placeholder="请输入安检审核人"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="安检审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择安检审核时间" v-decorator="['auditTime2']"
                                :trigger-change="true" :show-time="true"
                                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="验罐人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['surveyorName']" placeholder="请输入验罐人"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="验罐时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择验罐时间" v-decorator="['surveyorTime']"
                                :trigger-change="true" :show-time="true"
                                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="取样人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['samplingName']" placeholder="请输入取样人员"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="取样时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择取样时间" v-decorator="['samplingTime']"
                                :trigger-change="true" :show-time="true"
                                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="铅封人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['leadSealingName']"
                                placeholder="请输入铅封人员"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="铅封时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择铅封时间" v-decorator="['leadSealingTime']"
                                :trigger-change="true" :show-time="true"
                                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="磅单上传时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <j-date placeholder="请选择磅单上传时间" v-decorator="['poundListTime']"
                                :trigger-change="true" :show-time="true"
                                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item label="驳回原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
                            <a-input v-decorator="['rejectReason']" placeholder="请输入驳回原因"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
                        <a-button @click="submitForm">提 交</a-button>
                    </a-col>
                </a-row>
            </a-form>
        </j-form-container>
    </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'

export default {
    name: 'TankerRegistrationForm',
    components: {
    },
    props: {
        //流程表单data
        formData: {
            type: Object,
            default: () => { },
            required: false
        },
        //表单模式：true流程表单 false普通表单
        formBpm: {
            type: Boolean,
            default: false,
            required: false
        },
        //表单禁用
        disabled: {
            type: Boolean,
            default: false,
            required: false
        }
    },
    data() {
        return {
            form: this.$form.createForm(this),
            model: {},
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            confirmLoading: false,
            validatorRules: {
            },
            url: {
                add: "/tankerRegistration/tankerRegistration/add",
                edit: "/tankerRegistration/tankerRegistration/edit",
                queryById: "/tankerRegistration/tankerRegistration/queryById"
            }
        }
    },
    computed: {
        formDisabled() {
            if (this.formBpm === true) {
                if (this.formData.disabled === false) {
                    return false
                }
                return true
            }
            return this.disabled
        },
        showFlowSubmitButton() {
            if (this.formBpm === true) {
                if (this.formData.disabled === false) {
                    return true
                }
            }
            return false
        }
    },
    created() {
        //如果是流程中表单，则需要加载流程表单data
        this.showFlowData();
    },
    methods: {
        add() {
            this.edit({});
        },
        edit(record) {
            this.form.resetFields();
            this.model = Object.assign({}, record);
            this.visible = true;
            this.$nextTick(() => {
                this.form.setFieldsValue(pick(this.model, 'createTime', 'plateNo', 'trailerNo', 'driverName', 'idCard', 'phoneNum', 'healthCertificate',
                    'healthCertificateDate', 'fleet', 'isEdibleOilLabel', 'lastTimeUnloadingCompanyName1', 'lastTimeUnloadingCompanyName2',
                    'lastTimeUnloadingCompanyName3', 'lastTimeUnloadingGoodsName1', 'lastTimeUnloadingGoodsName2', 'lastTimeUnloadingGoodsName3',
                    'lastTimeUnloadingDate1', 'lastTimeUnloadingDate2', 'lastTimeUnloadingDate3', 'lastTimeUnloadingPhotos', 'lastTimeCleaningDate',
                    'lastTimeCleaningPhotos', 'transportStatus', 'takeDeliveryStatus', 'deliveryStatus', 'entryStatus', 'vehicle45Photo', 'back45Photo',
                    'tankPhoto', 'oilDischargePortPhoto', 'leadSealingPic', 'isOdor', 'auditName1', 'auditTime1', 'auditName2', 'auditTime2',
                    'surveyorName', 'surveyorTime', 'productionType', 'vehiclePhoto', 'documentation', 'screenshot', 'driverSign',
                    'rejectReason', 'storageTankPhoto', 'poundListPhoto', 'poundListTime', 'certificate', 'productLabel', 'poundListPhoto1',
                    'leadSealingPic1', 'samplingName', 'samplingTime', 'leadSealingName', 'leadSealingTime', 'receiptCompany', 'deliverCompany', 'weight',
                    'onboardRecordForm', 'samplingPhoto', 'otherCertificate'))
            })
        },
        //渲染流程表单数据
        showFlowData() {
            if (this.formBpm === true) {
                let params = { id: this.formData.dataId };
                getAction(this.url.queryById, params).then((res) => {
                    if (res.success) {
                        this.edit(res.result);
                    }
                });
            }
        },
        submitForm() {
            const that = this;
            // 触发表单验证
            this.form.validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true;
                    let httpurl = '';
                    let method = '';
                    if (!this.model.id) {
                        httpurl += this.url.add;
                        method = 'post';
                    } else {
                        httpurl += this.url.edit;
                        method = 'put';
                    }
                    let formData = Object.assign(this.model, values);
                    console.log("表单提交数据", formData)
                    httpAction(httpurl, formData, method).then((res) => {
                        if (res.success) {
                            that.$message.success(res.message);
                            that.$emit('ok');
                        } else {
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                }

            })
        },
        popupCallback(row) {
            this.form.setFieldsValue(pick(row, 'createTime', 'plateNo', 'trailerNo', 'driverName', 'idCard', 'phoneNum', 'healthCertificate',
                'healthCertificateDate', 'fleet', 'isEdibleOilLabel', 'lastTimeUnloadingCompanyName1', 'lastTimeUnloadingCompanyName2',
                'lastTimeUnloadingCompanyName3', 'lastTimeUnloadingGoodsName1', 'lastTimeUnloadingGoodsName2', 'lastTimeUnloadingGoodsName3',
                'lastTimeUnloadingDate1', 'lastTimeUnloadingDate2', 'lastTimeUnloadingDate3', 'lastTimeUnloadingPhotos', 'lastTimeCleaningDate',
                'lastTimeCleaningPhotos', 'transportStatus', 'takeDeliveryStatus', 'deliveryStatus', 'entryStatus', 'vehicle45Photo', 'back45Photo',
                'tankPhoto', 'oilDischargePortPhoto', 'leadSealingPic', 'isOdor', 'auditName1', 'auditTime1', 'auditName2', 'auditTime2',
                'surveyorName', 'surveyorTime', 'productionType', 'vehiclePhoto', 'documentation', 'screenshot', 'driverSign',
                'rejectReason', 'storageTankPhoto', 'poundListPhoto', 'poundListTime', 'certificate', 'productLabel', 'poundListPhoto1', 'leadSealingPic1',
                'samplingName', 'samplingTime', 'leadSealingName', 'leadSealingTime', 'receiptCompany', 'deliverCompany', 'weight', 'onboardRecordForm',
                'samplingPhoto', 'otherCertificate'))
        },
    }
}
</script>